package cn.doitedu.day04

object ApplyDemo {

  def main(args: Array[String]): Unit = {

    //初始化object
    //val a = MyArray
    val r = MyArray()
    println(r)

    //等价于下面的写法
    val r1 = MyArray.apply()
    println(r1)

    MyArray.apply(5)
    MyArray(5)

    MyArray.apply("tom", 6)
    val r2 = MyArray("tom", 6)

    println(r2)
  }

}

object MyArray {

  //当object中有一个特殊的方法名，叫apply时，可以省略
  def apply(): Unit = {
    println("666")
  }

  def apply(age: Int): Unit = {
    println(age)
  }

  def apply(name: String, age: Int) = {
    name + ", " + age
  }


  val arr1 = Array(1, 2, 3, 4, 5, 6, 7, 8, 9)
  val arr2 = Array.apply(1, 2, 3, 4, 5, 6, 7, 8, 9)

  //动态初始化一个定长数组
  val arr3 = new Array[Int](9)


}
